/*
 * ToolsPanel.fx
 *
 * Created on 06-Feb-2009, 11:55:31
 */

package portfoliocreator;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.ext.swing.SwingButton;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.effect.Shadow;
import javafx.scene.effect.DropShadow;
import javafx.scene.Group;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.image.Image;
import widgets.NextStepButtonWidget;
import widgets.SplashWidget;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import widgets.ToolBarMenuWidget;
import javafx.animation.Interpolator;
import widgets.ImportDialogWidget;


/**
 * @author beol
 */

bound function test(): Boolean {

    return true;
}

public class ToolsPanel extends CustomNode{

    def mainContainer: Group = Group {
    };

    var splash: SplashWidget = SplashWidget {
        x: 45
        y: 20
    }

    var startDrowToolPanel: Boolean = bind splash.isSplashFinished on replace do {
        menu.visible = true;
        createMenu.play();
        menu.isImport = true;
    }

    def menu:ToolBarMenuWidget = ToolBarMenuWidget {
        x: 15
        y: 5
        opacity: bind menuOpacity
    }

    var menuOpacity: Number = 0.0;

    var createMenu: Timeline = Timeline {
        repeatCount: 1
        keyFrames : [
            KeyFrame {
                time : 0.5s
                values: menuOpacity => 0.0;
            },
            KeyFrame {
                time: 1.5s
                values: menuOpacity => 1.0 tween Interpolator.LINEAR;
                action: function() {
                    menu.isImport = false;
                    menu.isImport = true;
                }
            }
        ]
    }

    var importDialogOpacity:Number = 0.0;

    def importDialog:ImportDialogWidget = ImportDialogWidget {
        x: 30
        y: 80
        visible: false
        opacity: bind importDialogOpacity;
    }

    var isImport = bind menu.isImport on replace do {
        if (isImport == true) {
            showImportDialog.rate = 1;
            showImportDialog.play();
        } else {
            showImportDialog.rate = -1;
            showImportDialog.play();
        }
    }

    def showImportDialog: Timeline = Timeline {
        keyFrames: [
            KeyFrame {
                time: 0s
                values: importDialogOpacity => 0.0
                action: function() {
                    if (importDialog.visible) {
                        importDialog.visible = false;
                        delete importDialog from mainContainer.content;
                    } else {
                        insert importDialog into mainContainer.content;
                        importDialog.visible = true;
                    }
                }
            },
            KeyFrame {
                time: 0.5s
                values: importDialogOpacity => 1.0 tween Interpolator.LINEAR;
            }
        ]
    }

    protected override function create(): Node {
        //menu.visible = false;
        //mainContainer.content = [splash, menu];
        //splash.play();
        mainContainer.content = [menu];
        createMenu.play();
        //showImportDialog.play();
        return mainContainer;
    }
}
